package com.yingdong.logic.controller;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.yingdong.db.Userhouse;
import com.yingdong.logic.domain.GameUser;
import com.yingdong.message.HouseMessage;

public class HouseController extends GameController {

	public Map<Integer, Userhouse> houseMap = new ConcurrentHashMap<>();

	public HouseController(GameUser user) {
		super(user);

	}

	@Override
	public void init() {
		List<Userhouse> list = Userhouse.getInstance().selectObjectsByCondition("userId", getUserId());
		for (Userhouse userhouse : list) {
			houseMap.put(userhouse.getSlotId(), userhouse);
		}
	}

	@Override
	public void firstEnter() {
		new HouseMessage(houseMap.values()).sendToClient(getSessionId());
	}

	@Override
	public void saveDB() {
		Userhouse.getInstance().saveBatch(houseMap.values());
	}

}
